package com.itboye.sunsun.buy.ui;

import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

import com.itboye.sunsun.R;
import com.itboye.sunsun.application.App;
import com.itboye.sunsun.beans.DianPuYouHuiBean;
import com.itboye.sunsun.beans.GoodsDetailBean;
import com.itboye.sunsun.beans.RedPacketBean;
import com.itboye.sunsun.beans.GoodsDetailBean.Group;
import com.itboye.sunsun.beans.LocationBean;
import com.itboye.sunsun.beans.OrderQueRenDingDan;
import com.itboye.sunsun.beans.GoodsDetailBean.SkuCombinationBean;
import com.itboye.sunsun.beans.ShopCarBean;
import com.itboye.sunsun.constants.SPContants;
import com.itboye.sunsun.network.HttpRequest;
import com.itboye.sunsun.person.ui.SelectAddressActivity;
import com.itboye.sunsun.shop.ui.AllShopActivity;
import com.itboye.sunsun.support.BaseActivity;
import com.itboye.sunsun.utils.DebugLog;
import com.itboye.sunsun.utils.DebugToast;
import com.itboye.sunsun.utils.DensityUtil;
import com.itboye.sunsun.utils.DoubleParse;
import com.itboye.sunsun.utils.IntegerParse;
import com.itboye.sunsun.utils.SPUtils;
import com.itboye.sunsun.utils.Sha1Md5Util;
import com.itboye.sunsun.utils.XImageLoader;
import com.itboye.sunsun.volley.CodeErrorException;
import com.itboye.sunsun.volley.MyJsonRequest;
import com.itboye.sunsun.volley.MyJsonRequest.Builder;
import com.itboye.sunsun.volley.XErrorListener;
import com.itboye.sunsun.volley.XRequestListener;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class QueRenDingDan extends BaseActivity {

	double shuliangAndJiage = 0, hongBao = 0, dianPuYouHui = 0, yunfei2 = 0;
	boolean isHotGoods;

	ViewGroup addAddress;
	// ImageView img;
	// TextView name;
	// TextView guige;
	// TextView jiage;
	// TextView shuliang;
	// View jian;
	// View jia;
	// EditText input;
	TextView yunfei;
	TextView yunfeiinfo;
	EditText liuyan;

	View daifu;
	View niming;

	TextView heji;
	View ok;

	TextView shouhuoInfo;
	// GoodsDetailBean goodsDetailBeans;
	// String pskuId;
	// int count;

	// int kuCunCount;
	double price = 0;// 总价格

	double dianpuyouhuiDouble = 0;
	double youhuiDouble = 0;
	int yunfeiInt;

	ViewGroup goodsList;
	TextView youhui;
	String shopcarId;

	String youhuiquanId;
	TextView dianPuyouhui;

	String shifoubaoyou;
	private String defaultid;
	TextView shangPinyouhui, shangPinyouhui2;
	double totalPrice;// 商品优惠总价格
	ViewGroup shangPinYouhui;
	String idCode = null;
	ArrayList<Double> qianBaoMoney = new ArrayList<>();
	ArrayList<String> idCodes = new ArrayList<>();
	ArrayList<String> condition = new ArrayList<>();
	int xiabiao;
	protected double max;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.activity_queren_dingdan);
		getAllLocation();
		int from = getIntent().getIntExtra("from", -1);
		if (from == 0) {
			// shopcarid
			shopcarId = getIntent().getStringExtra("shopcarid");// 立即购买
			init0();
		} else if (from == 1) {// 从购物车进入
			init1();
		}

		init();
		try {

			getDianPuYOuhui();
		} catch (Exception e) {
			// TODO: handle exception
		}
		try {
			getDefaultLocation();
		} catch (Exception e) {

		}
		jisuanZongjia();
	}

	private void jisuanZongjia() {
		// TODO Auto-generated method stub
		heji.setText("￥"
				+ (shuliangAndJiage - hongBao - dianPuYouHui - yunfei2 - totalPrice)
				+ "");
	}

	// 获取所有红包信息
	private void getData() {

		MyJsonRequest<List<RedPacketBean>> request = new MyJsonRequest.Builder<List<RedPacketBean>>()
				.apiVer("100")
				.typeKey("BY_RedEnvelope_query")
				.param("uid",
						(String) SPUtils.get(getApplicationContext(), null,
								SPContants.USER_ID, ""))
				.requestListener(new XRequestListener<List<RedPacketBean>>() {

					@Override
					public void onResponse(List<RedPacketBean> arg0) {
						for (int i = 0; i < arg0.size(); i++) {
							RedPacketBean bean = arg0.get(i);
							long time = Long.parseLong(bean.getGetTime())
									* 1000
									+ Long.parseLong(bean.getExpireTime())
									* 1000;// 过期时间
							long nowTime = new Date().getTime();// 当前时间
							if (time > nowTime) {// 未过期
								if (Integer.parseInt(bean.getUseStatus()) == 0) {// 未使用
									if (price >= Double.parseDouble(bean
											.getUseCondition())) {
										idCodes.add(bean.getId());
										qianBaoMoney.add(Double
												.parseDouble(bean.getMoney()));
										// condition
										// youhuiquanId = bean.getId();
									}
								}
							}

						}
						max = Double.parseDouble(qianBaoMoney.get(0) + "");
						for (int k = 0; k < qianBaoMoney.size(); k++) {
							if (max <= Double.parseDouble(qianBaoMoney.get(k)
									+ "")) {
								max = Double.parseDouble(qianBaoMoney.get(k)
										+ "");
								youhui.setText("红包  " + "-￥" + max);
								youhuiquanId = idCodes.get(k);
							}
						}
						price = price - max;
					}

				}).errorListener(new XErrorListener() {

					@Override
					public void onErrorResponse(Exception exception, int code,
							String msg) {

					}
				}).build();
		HttpRequest.getDefaultRequestQueue().add(request);
		hongBao = max;
		jisuanZongjia();
	}

	private List<LocationBean> list;

	// 获取全部地址
	public void getAllLocation() {
		MyJsonRequest<List<LocationBean>> request = new MyJsonRequest.Builder<List<LocationBean>>()
				.apiVer("100")
				.typeKey("BY_Address_queryNoPaging")
				.param("uid",
						(String) SPUtils.get(App.ctx, null, SPContants.USER_ID,
								""))

				.requestListener(new XRequestListener<List<LocationBean>>() {

					@Override
					public void onResponse(List<LocationBean> myList) {
						// TODO Auto-generated method stub

						// 遍历全部地址，如果某个地址是默认地址，就将他放在集合的第一个
						for (int i = 0; i < myList.size(); i++) {
							if (myList.get(i).getId().equals(defaultid)) {

								LocationBean defaultbean = myList.get(i);
								myList.remove(i);
								myList.add(0, defaultbean);
							}
						}

						DebugLog.v("result", myList.size() + "");
						list = myList;
						String id = list.get(0).getId();
						String name = list.get(0).getContactname();
						String phone = list.get(0).getMobile();
						String detail = list.get(0).getDetailinfo();
						String wholelocation = list.get(0).getProvince()
								+ list.get(0).getCity() + list.get(0).getArea();
						shouhuoInfo.setText("收货人：" + name + "   " + phone
								+ "\n收货地址：" + wholelocation + detail);
						shouhuoInfo.setTag(id);
						getYunFei(id);

					}
				}).errorListener(new XErrorListener() {

					@Override
					public void onErrorResponse(Exception exception, int code,
							String msg) {
//						Toast.makeText(App.ctx, code + "", 0).show();
//						if (exception instanceof CodeErrorException) {
//							// Toast.makeText(App.ctx, msg, 0).show();
//						} else {
//							Toast.makeText(App.ctx, exception.toString(), 0)
//									.show();
//						}

					}
				}).build();
		HttpRequest.getDefaultRequestQueue().add(request);

	}

	private void getDianPuYOuhui() {

		MyJsonRequest<DianPuYouHuiBean> request = new MyJsonRequest.Builder<DianPuYouHuiBean>()
				.apiVer("100").typeKey("BY_StorePromotion_getInfo")
				.param("store_id", "2")

				.requestListener(new XRequestListener<DianPuYouHuiBean>() {

					@Override
					public void onResponse(DianPuYouHuiBean arg0) {
						double price = DoubleParse.parse(
								(String) heji.getTag(), 0);

						if (DoubleParse.parse(arg0.getCondition(), 0) <= price) {
							yunfei2 = Double.parseDouble(arg0
									.getDiscountMoney());
							dianPuyouhui.setText("￥" + arg0.getDiscountMoney());
							dianPuyouhui.setTag(arg0.getDiscountMoney());

							if ("1".equals(arg0.getFreeShipping())) {
								yunfei.setText("包邮");
								yunfei.setTag(0);
								shifoubaoyou = arg0.getFreeShipping();
							}
						} else {
							dianPuyouhui.setText("0");
							dianPuyouhui.setTag("0");
							shifoubaoyou = "0";
						}

						changePrice();

					}
				}).errorListener(new XErrorListener() {

					@Override
					public void onErrorResponse(Exception exception, int code,
							String msg) {

					}
				}).build();

		HttpRequest.getDefaultRequestQueue().add(request);

	}

	private void init1() {
		// TODO Auto-generated method stub
		// intent.putExtra("list", list);
		// intent.putExtra("price",(String) heji.getTag());
		ArrayList<ShopCarBean> list = (ArrayList<ShopCarBean>) getIntent()
				.getSerializableExtra("list");
		String price = getIntent().getStringExtra("price");
		int youhuiJia = 0;
		int h = DensityUtil.dip2px(0.5f);
		StringBuilder sb = new StringBuilder();
		for (int j = 0; j < list.size(); j++) {
			ShopCarBean shopCarBean = list.get(j);
			sb.append(shopCarBean.getId()).append(",");
			View v = LayoutInflater.from(getApplicationContext()).inflate(
					R.layout.item_queren_order, null);
			ImageView img = (ImageView) v.findViewById(R.id.img);
			TextView name = (TextView) v.findViewById(R.id.name);
			TextView guige = (TextView) v.findViewById(R.id.guige);
			TextView jiage = (TextView) v.findViewById(R.id.jiage);
			TextView shuliang = (TextView) v.findViewById(R.id.shuliang);

			name.setText(shopCarBean.getName());
			guige.setText(shopCarBean.getSkuDesc());
			jiage.setText(shopCarBean.getPrice());
			shuliang.setText("x" + shopCarBean.getCount());
			XImageLoader.load(shopCarBean.getIconUrl(), img);
			System.out.println(shopCarBean.getGroup() + "group");
		
			if (shopCarBean.getGroup() != null) {
				for (int i = 0; i < shopCarBean.getGroup().size(); i++) {
					View view = LayoutInflater.from(this).inflate(
							R.layout.item_shangpinyouhui, null);
					shangPinyouhui = (TextView) view
							.findViewById(R.id.shangPinyouhui);
					shangPinyouhui2 = (TextView) view
							.findViewById(R.id.shangPinyouhui2);
					totalPrice += Double.parseDouble(Double
							.parseDouble(shopCarBean.getGroup().get(i)
									.getPrice())
							* Integer.parseInt(shopCarBean.getCount()) + "");
					shangPinyouhui2.setText("-￥"
							+ list.get(j).getGroup().get(i).getPrice());
					youhuiJia += Double.parseDouble(list.get(j).getGroup()
							.get(i).getPrice());
					shangPinyouhui.setText(list.get(j).getGroup().get(i)
							.getName()
							+ "(" + list.get(j).getName() + ")");
					shangPinYouhui.addView(view);
				}
				if (youhuiJia > 0) {
					isHotGoods = true;
				} else {
					isHotGoods = false;
				}
			} else {
				isHotGoods = false;
			}
			goodsList.addView(v);
			View divider = new View(getApplicationContext());
			divider.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
					h));
			divider.setBackgroundColor(getResources().getColor(
					R.color.backgroundColor));
			goodsList.addView(divider);
		}
		// for (ShopCarBean shopCarBean : list) {
		// sb.append(shopCarBean.getId()).append(",");
		//
		//
		// }
		System.out.println(totalPrice + ":" + Double.parseDouble(price));
		shuliangAndJiage = DoubleParse.parse(price, 0);
		price = Double.parseDouble(price) - totalPrice-youhuiJia + "";
		QueRenDingDan.this.price = DoubleParse.parse(price, 0);
		if (isHotGoods == false)
			getData();
		else {
			youhui.setText("该订单已含有优惠，不能使用红包");
		}
		heji.setText("￥" + QueRenDingDan.this.price);
		heji.setTag(QueRenDingDan.this.price);
		String s = sb.toString();
		if (s.length() > 1) {
			shopcarId = s.substring(0, s.length() - 1);
		}

	}

	private void init() {
		// TODO Auto-generated method stub
		addAddress.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Intent intent = new Intent(getApplicationContext(),
						SelectAddressActivity.class);
				startActivityForResult(intent, 1);
			}
		});
		daifu.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				v.setSelected(!v.isSelected());
				if (v.isSelected()) {
					v.setBackgroundResource(R.drawable.ic_black_checkbox);
				} else {
					v.setBackgroundResource(R.drawable.ic_orange_checkbox_selected);
				}

			}
		});

		niming.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				v.setSelected(!v.isSelected());
				if (v.isSelected()) {
					v.setBackgroundResource(R.drawable.ic_black_checkbox);
				} else {
					v.setBackgroundResource(R.drawable.ic_orange_checkbox_selected);
				}
			}
		});

		findViewById(R.id.back).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});

		findViewById(R.id.youhuiContainer).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!isHotGoods) {
							Intent intent = new Intent(getApplicationContext(),
									RedPacketActivity.class);
							intent.putExtra("price", price);
							// TODO Auto-generated method stub
							startActivityForResult(intent, 2);
						} else {
							// Toast.makeText(App.ctx, "不能使用红包", 0).show();
						}
					}
				});

		findViewById(R.id.ok).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if ( shouhuoInfo.getTag() == null) {
					Toast.makeText(getApplicationContext(), "请选择收货地址", 1)
							.show();
					return;
				}

				// int yf = (Integer) yunfei.getTag();
				//
				// double yh;
				// if (youhui.getTag() == null) {
				// yh = 0;
				// } else {
				// yh = (Double) youhui.getTag();
				// }
				// double count = price - yh + yf
				// - DoubleParse.parse((String) dianPuyouhui.getTag(), 0);
				// DebugToast.show(count, 1);

				tijiaoDingdan();
				QueRenDingDan.this.finish();
			}

		});
	}

	private void tijiaoDingdan() {
		System.out.println("youhuiquanId" + youhuiquanId);
		Builder<OrderQueRenDingDan> builder = new MyJsonRequest.Builder<OrderQueRenDingDan>()
				.apiVer("100")
				.typeKey("BY_Orders_add")
				.param("cart_ids", shopcarId)
				.param("note", liuyan.getText().toString())
				.param("address_id", shouhuoInfo.getTag())
				.param("uid",
						(String) SPUtils.get(getApplicationContext(), null,
								SPContants.USER_ID, ""))
				.requestListener(new XRequestListener<OrderQueRenDingDan>() {

					@Override
					public void onResponse(OrderQueRenDingDan arg0) {

						String name = arg0.getName();
						String desc = arg0.getDesc();

						name = URLDecoder.decode(name);
						desc = URLDecoder.decode(desc);

						String str = arg0.getCode() + name + desc
								+ arg0.getTotalPrice();

						str = URLEncoder.encode(str);

						str = str.toLowerCase();

						str = Sha1Md5Util.SHA1(Sha1Md5Util.MD5(str));

						str = str + "ITBOYE_PAY_DASFSAFKL";

						str = Sha1Md5Util.MD5(str);

						if (arg0.getKey().equals(str)) {
							Intent intent = new Intent(getApplicationContext(),
									QueRenZhiFuActivity.class);
							intent.putExtra("what", arg0);
							startActivity(intent);
						} else {
							Toast.makeText(getApplicationContext(), "订单异常", 1)
									.show();
						}

						// DebugToast.show("付款。。。", 1);

					}
				}).errorListener(new XErrorListener() {

					@Override
					public void onErrorResponse(Exception exception, int code,
							String msg) {

					}
				});

		if (youhuiquanId != null) {
			builder.param("idcode", youhuiquanId);
		}
		//
		HttpRequest.getDefaultRequestQueue().add(builder.build());

	}

	private void init0() {
		// TODO Auto-generated method stub
		ImageView img;
		TextView name;
		TextView guige;
		TextView jiage;
		TextView shuliang;
		View v = LayoutInflater.from(getApplicationContext()).inflate(
				R.layout.item_queren_order, null);
		img = (ImageView) v.findViewById(R.id.img);
		name = (TextView) v.findViewById(R.id.name);
		guige = (TextView) v.findViewById(R.id.guige);
		jiage = (TextView) v.findViewById(R.id.jiage);
		shuliang = (TextView) v.findViewById(R.id.shuliang);

		String pskuId = getIntent().getStringExtra("id");
		GoodsDetailBean goodsDetailBeans = (GoodsDetailBean) getIntent()
				.getSerializableExtra("bean");
		int count = IntegerParse.parse(getIntent().getStringExtra("count"), 0);
		name.setText(goodsDetailBeans.getName());
		int has = goodsDetailBeans.getHasSku();
		if (has == 1) {
			List<SkuCombinationBean> list = goodsDetailBeans.getSkuList();
			for (SkuCombinationBean skuCombinationBean : list) {
				if (skuCombinationBean.getId().equals(pskuId)) {
					price = DoubleParse.parse(skuCombinationBean.getPrice(), 0);
					guige.setText(skuCombinationBean.getSkuDesc());
					// int
					// kuCunCount=IntegerParse.parse(skuCombinationBean.getQuantity(),
					// 0);
					break;
				}
			}
		} else {
			price = DoubleParse.parse(goodsDetailBeans.getSkuInfo().getPrice(),
					0);
			// kuCunCount=IntegerParse.parse(goodsDetailBeans.getSkuInfo().getQuantity(),
			// 0);
		}
		List<Group> group = goodsDetailBeans.getGroup();
		if (group != null) {
			for (int i = 0; i < goodsDetailBeans.getGroup().size(); i++) {
				View view = LayoutInflater.from(this).inflate(
						R.layout.item_shangpinyouhui, null);
				shangPinyouhui = (TextView) view
						.findViewById(R.id.shangPinyouhui);
				shangPinyouhui2 = (TextView) view
						.findViewById(R.id.shangPinyouhui2);
				totalPrice += Double.parseDouble(Double
						.parseDouble(goodsDetailBeans.getGroup().get(i)
								.getPrice())
						* count + "");
				shangPinyouhui.setText(group.get(0).getName());
				shangPinyouhui2.setText("-￥" + totalPrice);
				shangPinYouhui.addView(view);
			}
			if (totalPrice > 0) {
				isHotGoods = true;
			} else {
				isHotGoods = false;
			}
		} else {
			isHotGoods = false;
		}

		jiage.setText("￥" + price);
		jiage.setTag(price);
		shuliang.setText("x" + count);
		shuliangAndJiage = count * price;
		String p = String.format("%.2f", count * price);
		p = (Double.parseDouble(p) - totalPrice) + "";
		XImageLoader.load(goodsDetailBeans.getMainImg(), img);

		goodsList.addView(v);
		price = count * price - totalPrice;
		if (isHotGoods) {
			youhui.setText("该订单已含有优惠，不能使用红包");
		} else {
			getData();

		}
		heji.setText("￥" + price);
		heji.setTag(price + "");
	}

	@Override
	protected void onActivityResult(int arg0, int arg1, Intent intent) {
		// TODO Auto-generated method stub
		super.onActivityResult(arg0, arg1, intent);
		if (arg1 != RESULT_OK) {
			return;
		}
		if (arg0 == 1) {
			String id = intent.getStringExtra("id");
			String wholelocation = intent.getStringExtra("wholelocation");
			String detail = intent.getStringExtra("detail");
			String zipcode = intent.getStringExtra("zipcode");
			String name = intent.getStringExtra("name");
			String phone = intent.getStringExtra("phone");

			shouhuoInfo.setText("收货人：" + name + "   " + phone + "\n收货地址："
					+ wholelocation + detail);
			shouhuoInfo.setTag(id);
			getYunFei(id);

		} else if (arg0 == 2) {
			String p = intent.getStringExtra("price");
			youhui.setText("");
			youhui.setText("红包   -￥" + Double.parseDouble(p));
			hongBao = Double.parseDouble(p);
			youhui.setTag(DoubleParse.parse(p, 0));
			price = price - DoubleParse.parse(p, 0);
			String s = String.format("%.2f", price - DoubleParse.parse(p, 0));
			heji.setText("￥" + s);
			heji.setTag(s);

			youhuiquanId = intent.getStringExtra("id");

			changePrice();
			jisuanZongjia();
		}
	}

	private void changePrice() {

		int yf = (Integer) yunfei.getTag();

		double yh;
		if (youhui.getTag() == null) {
			yh = 0;
		} else {
			yh = (Double) youhui.getTag();
		}

		// Toast.makeText(App.ctx, "优惠"+yh, 0).show();
		System.out.println(">>>>>店铺有机会" + dianPuyouhui.getTag() + "");
		// double count = price - yh
		// - DoubleParse.parse((String) dianPuyouhui.getTag(), 0);
		//
		// String p = String.format("%.2f", count);
		heji.setText(price + "");
		heji.setTag(price + "");
	}

	private void getYunFei(String id) {

		MyJsonRequest<Integer> request = new MyJsonRequest.Builder<Integer>()
				.apiVer("100")
				.typeKey("BY_Freight_cost")
				.param("cart_ids", shopcarId)
				.param("address_id", id)
				.param("uid",
						(String) SPUtils.get(getApplicationContext(), null,
								SPContants.USER_ID, ""))
				.requestListener(new XRequestListener<Integer>() {

					@Override
					public void onResponse(Integer arg0) {

						// Toast.makeText(App.ctx, arg0, 0).show();

						// 如果运费为0
						if (arg0 == 0) {

							yunfei.setTag(arg0);
							yunfei.setText("包邮");

							yunfeiInt = arg0;
						} else {

							// 如果店铺优惠是包邮
							if (shifoubaoyou.equals("1")) {
								yunfei.setText("包邮");

								yunfeiInt = arg0;
								yunfei.setTag(0);
							}
							// 如果不包邮
							else {

								yunfei.setText("￥" + arg0);

								yunfeiInt = arg0;
								yunfei.setTag(arg0);
							}
						}
						changePrice();

					}
				}).errorListener(new XErrorListener() {

					@Override
					public void onErrorResponse(Exception exception, int code,
							String msg) {

					}
				}).build();

		HttpRequest.getDefaultRequestQueue().add(request);
	}

	// 获取默认地址ID
	public void getDefaultLocation() {
		MyJsonRequest<String> request = new MyJsonRequest.Builder<String>()
				.apiVer("100")
				.typeKey("BY_Address_getDefaultAddress")
				.param("uid",
						(String) SPUtils.get(App.ctx, null, SPContants.USER_ID,
								""))

				.requestListener(new XRequestListener<String>() {

					@Override
					public void onResponse(String response) {
						// TODO Auto-generated method stub
						DebugLog.v("result", response.toString());

						if (!response.toString().equals("0")) {
							defaultid = response.toString();
							getSingleLocation(response.toString());
						} else {
							getAllLocation();
						}

					}
				}).errorListener(new XErrorListener() {

					@Override
					public void onErrorResponse(Exception exception, int code,
							String msg) {
						Toast.makeText(App.ctx, code + "", 0).show();
						if (exception instanceof CodeErrorException) {
							// Toast.makeText(App.ctx, msg, 0).show();
						} else {
							Toast.makeText(App.ctx, exception.toString(), 0)
									.show();
						}

					}
				}).build();
		HttpRequest.getDefaultRequestQueue().add(request);
	}

	// 获取单个地址
	public void getSingleLocation(String response) {
		// Toast.makeText(App.ctx, (String)SPUtils.get(App.ctx, null,
		// SPContants.USER_ID, ""), 0).show();
		MyJsonRequest<LocationBean> request = new MyJsonRequest.Builder<LocationBean>()
				.apiVer("100")
				.typeKey("BY_Address_getInfo")
				.param("uid",
						(String) SPUtils.get(App.ctx, null, SPContants.USER_ID,
								"")).param("id", response)

				.requestListener(new XRequestListener<LocationBean>() {

					@Override
					public void onResponse(LocationBean response) {

						String id = response.getId();
						String name = response.getContactname();
						String phone = response.getMobile();
						String detail = response.getDetailinfo();
						String wholelocation = response.getProvince()
								+ response.getCity() + response.getArea();
						shouhuoInfo.setText("收货人：" + name + "   " + phone
								+ "\n收货地址：" + wholelocation + detail);
						shouhuoInfo.setTag(id);
						getYunFei(id);
					}
				}).errorListener(new XErrorListener() {

					@Override
					public void onErrorResponse(Exception exception, int code,
							String msg) {
						Toast.makeText(App.ctx, code + "", 0).show();
						if (exception instanceof CodeErrorException) {
							// Toast.makeText(App.ctx, msg, 0).show();
						} else {
							Toast.makeText(App.ctx, exception.toString(), 0)
									.show();
						}

					}
				}).build();
		HttpRequest.getDefaultRequestQueue().add(request);
	}

}
